﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BusinessObjects;
using DataAccess;

namespace QuanLyHopDong
{
    public partial class ChucVuDetailView : Form
    {
        public event EventHandler SaveChanged;
        public event EventHandler DeleteChanged;
        private BindingList<ChucVu> bindingListChucVu;
        private ChucVu _chucVu;

        public ChucVuDetailView()
        {
            InitializeComponent();
        }
        public ChucVuDetailView(ChucVu chucVu)
        {
            InitializeComponent();

            bindingListChucVu = new BindingList<ChucVu>();
            _chucVu = chucVu;
            bindingListChucVu.Add(chucVu);

            bindingSource1.DataSource = bindingListChucVu;
            layoutControl1.Refresh();
        }

        private void Luu()
        {
            if (_chucVu.Oid == -1)
            {
                DataAccessObject.ChucVu.Insert(_chucVu);
                OnSaveChanged();
            }
            else
                DataAccessObject.ChucVu.Update(_chucVu);
        }

        private void XoaForm()
        {
        }

        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
         }

        private void btnClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void btnLuuVaDong_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
            this.Close();
        }

        private void btnLuuVaMoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Luu();
            XoaForm();
        }

        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            OnDeleteChange();
            Close();
        }

        private void btnThem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }

        private void OnSaveChanged()
        {
            if (SaveChanged != null)
                SaveChanged(this, EventArgs.Empty);
        }
        private void OnDeleteChange()
        {
            if (DeleteChanged != null)
                DeleteChanged(this, EventArgs.Empty);
        }

    }
}
